﻿
#region Using directives

using System;
using System.Collections;
using System.Collections.Specialized;


using System.Web.Configuration;
using System.Data;
using System.Data.Common;
using System.Configuration.Provider;

using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

using InfoExpress.HIV.Domains;
using InfoExpress.HIV.DataAccess;
using InfoExpress.HIV.DataAccess.Bases;

#endregion

namespace InfoExpress.HIV.DataAccess.SqlClient
{
	/// <summary>
	/// This class is the Sql implementation of the NetTiersProvider.
	/// </summary>
	public sealed class SqlNetTiersProvider : InfoExpress.HIV.DataAccess.Bases.NetTiersProvider
	{
		private static object syncRoot = new Object();
		private string _applicationName;
        private string _connectionString;
        private bool _useStoredProcedure;
        string _providerInvariantName;
		
		/// <summary>
		/// Initializes a new instance of the <see cref="SqlNetTiersProvider"/> class.
		///</summary>
		public SqlNetTiersProvider()
		{	
		}		
		
		/// <summary>
        /// Initializes the provider.
        /// </summary>
        /// <param name="name">The friendly name of the provider.</param>
        /// <param name="config">A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.</param>
        /// <exception cref="T:System.ArgumentNullException">The name of the provider is null.</exception>
        /// <exception cref="T:System.InvalidOperationException">An attempt is made to call <see cref="M:System.Configuration.Provider.ProviderBase.Initialize(System.String,System.Collections.Specialized.NameValueCollection)"></see> on a provider after the provider has already been initialized.</exception>
        /// <exception cref="T:System.ArgumentException">The name of the provider has a length of zero.</exception>
		public override void Initialize(string name, NameValueCollection config)
        {
            // Verify that config isn't null
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            // Assign the provider a default name if it doesn't have one
            if (String.IsNullOrEmpty(name))
            {
                name = "SqlNetTiersProvider";
            }

            // Add a default "description" attribute to config if the
            // attribute doesn't exist or is empty
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", "NetTiers Sql provider");
            }

            // Call the base class's Initialize method
            base.Initialize(name, config);

            // Initialize _applicationName
            _applicationName = config["applicationName"];

            if (string.IsNullOrEmpty(_applicationName))
            {
                _applicationName = "/";
            }
            config.Remove("applicationName");


            #region "Initialize UseStoredProcedure"
            string storedProcedure  = config["useStoredProcedure"];
           	if (string.IsNullOrEmpty(storedProcedure))
            {
                throw new ProviderException("Empty or missing useStoredProcedure");
            }
            this._useStoredProcedure = Convert.ToBoolean(config["useStoredProcedure"]);
            config.Remove("useStoredProcedure");
            #endregion

			#region ConnectionString

			// Initialize _connectionString
			_connectionString = config["connectionString"];
			config.Remove("connectionString");

			string connect = config["connectionStringName"];
			config.Remove("connectionStringName");

			if ( String.IsNullOrEmpty(_connectionString) )
			{
				if ( String.IsNullOrEmpty(connect) )
				{
					throw new ProviderException("Empty or missing connectionStringName");
				}

				if ( DataRepository.ConnectionStrings[connect] == null )
				{
					throw new ProviderException("Missing connection string");
				}

				_connectionString = DataRepository.ConnectionStrings[connect].ConnectionString;
			}

            if ( String.IsNullOrEmpty(_connectionString) )
            {
                throw new ProviderException("Empty connection string");
			}

			#endregion
            
             #region "_providerInvariantName"

            // initialize _providerInvariantName
            this._providerInvariantName = config["providerInvariantName"];

            if (String.IsNullOrEmpty(_providerInvariantName))
            {
                throw new ProviderException("Empty or missing providerInvariantName");
            }
            config.Remove("providerInvariantName");

            #endregion

        }
		
		/// <summary>
		/// Creates a new <c cref="TransactionManager"/> instance from the current datasource.
		/// </summary>
		/// <returns></returns>
		public override TransactionManager CreateTransaction()
		{
			return new TransactionManager(this._connectionString);
		}
		
		/// <summary>
		/// Gets a value indicating whether to use stored procedure or not.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this repository use stored procedures; otherwise, <c>false</c>.
		/// </value>
		public bool UseStoredProcedure
		{
			get {return this._useStoredProcedure;}
			set {this._useStoredProcedure = value;}
		}
		
		 /// <summary>
        /// Gets or sets the connection string.
        /// </summary>
        /// <value>The connection string.</value>
		public string ConnectionString
		{
			get {return this._connectionString;}
			set {this._connectionString = value;}
		}
		
		/// <summary>
	    /// Gets or sets the invariant provider name listed in the DbProviderFactories machine.config section.
	    /// </summary>
	    /// <value>The name of the provider invariant.</value>
	    public string ProviderInvariantName
	    {
	        get { return this._providerInvariantName; }
	        set { this._providerInvariantName = value; }
	    }		
		
		///<summary>
		/// Indicates if the current <c cref="NetTiersProvider"/> implementation supports Transacton.
		///</summary>
		public override bool IsTransactionSupported
		{
			get
			{
				return true;
			}
		}

		
		#region "TrangThaiProvider"
			
		private SqlTrangThaiProvider innerSqlTrangThaiProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="TrangThai"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override TrangThaiProviderBase TrangThaiProvider
		{
			get
			{
				if (innerSqlTrangThaiProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlTrangThaiProvider == null)
						{
							this.innerSqlTrangThaiProvider = new SqlTrangThaiProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlTrangThaiProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlTrangThaiProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlTrangThaiProvider SqlTrangThaiProvider
		{
			get {return TrangThaiProvider as SqlTrangThaiProvider;}
		}
		
		#endregion
		
		
		#region "BenhNhanDangKyProvider"
			
		private SqlBenhNhanDangKyProvider innerSqlBenhNhanDangKyProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="BenhNhanDangKy"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override BenhNhanDangKyProviderBase BenhNhanDangKyProvider
		{
			get
			{
				if (innerSqlBenhNhanDangKyProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlBenhNhanDangKyProvider == null)
						{
							this.innerSqlBenhNhanDangKyProvider = new SqlBenhNhanDangKyProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlBenhNhanDangKyProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlBenhNhanDangKyProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlBenhNhanDangKyProvider SqlBenhNhanDangKyProvider
		{
			get {return BenhNhanDangKyProvider as SqlBenhNhanDangKyProvider;}
		}
		
		#endregion
		
		
		#region "SUsersProvider"
			
		private SqlSUsersProvider innerSqlSUsersProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="SUsers"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override SUsersProviderBase SUsersProvider
		{
			get
			{
				if (innerSqlSUsersProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlSUsersProvider == null)
						{
							this.innerSqlSUsersProvider = new SqlSUsersProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlSUsersProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlSUsersProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlSUsersProvider SqlSUsersProvider
		{
			get {return SUsersProvider as SqlSUsersProvider;}
		}
		
		#endregion
		
		
		#region "ThayDoiPhacDoProvider"
			
		private SqlThayDoiPhacDoProvider innerSqlThayDoiPhacDoProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="ThayDoiPhacDo"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ThayDoiPhacDoProviderBase ThayDoiPhacDoProvider
		{
			get
			{
				if (innerSqlThayDoiPhacDoProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlThayDoiPhacDoProvider == null)
						{
							this.innerSqlThayDoiPhacDoProvider = new SqlThayDoiPhacDoProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlThayDoiPhacDoProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlThayDoiPhacDoProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlThayDoiPhacDoProvider SqlThayDoiPhacDoProvider
		{
			get {return ThayDoiPhacDoProvider as SqlThayDoiPhacDoProvider;}
		}
		
		#endregion
		
		
		#region "ThayDoiDieuTriProvider"
			
		private SqlThayDoiDieuTriProvider innerSqlThayDoiDieuTriProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="ThayDoiDieuTri"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ThayDoiDieuTriProviderBase ThayDoiDieuTriProvider
		{
			get
			{
				if (innerSqlThayDoiDieuTriProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlThayDoiDieuTriProvider == null)
						{
							this.innerSqlThayDoiDieuTriProvider = new SqlThayDoiDieuTriProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlThayDoiDieuTriProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlThayDoiDieuTriProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlThayDoiDieuTriProvider SqlThayDoiDieuTriProvider
		{
			get {return ThayDoiDieuTriProvider as SqlThayDoiDieuTriProvider;}
		}
		
		#endregion
		
		
		#region "UtPhacdoProvider"
			
		private SqlUtPhacdoProvider innerSqlUtPhacdoProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="UtPhacdo"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override UtPhacdoProviderBase UtPhacdoProvider
		{
			get
			{
				if (innerSqlUtPhacdoProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlUtPhacdoProvider == null)
						{
							this.innerSqlUtPhacdoProvider = new SqlUtPhacdoProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlUtPhacdoProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlUtPhacdoProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlUtPhacdoProvider SqlUtPhacdoProvider
		{
			get {return UtPhacdoProvider as SqlUtPhacdoProvider;}
		}
		
		#endregion
		
		
		#region "UtDmdvProvider"
			
		private SqlUtDmdvProvider innerSqlUtDmdvProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="UtDmdv"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override UtDmdvProviderBase UtDmdvProvider
		{
			get
			{
				if (innerSqlUtDmdvProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlUtDmdvProvider == null)
						{
							this.innerSqlUtDmdvProvider = new SqlUtDmdvProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlUtDmdvProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlUtDmdvProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlUtDmdvProvider SqlUtDmdvProvider
		{
			get {return UtDmdvProvider as SqlUtDmdvProvider;}
		}
		
		#endregion
		
		
		#region "UtDmxnProvider"
			
		private SqlUtDmxnProvider innerSqlUtDmxnProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="UtDmxn"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override UtDmxnProviderBase UtDmxnProvider
		{
			get
			{
				if (innerSqlUtDmxnProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlUtDmxnProvider == null)
						{
							this.innerSqlUtDmxnProvider = new SqlUtDmxnProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlUtDmxnProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlUtDmxnProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlUtDmxnProvider SqlUtDmxnProvider
		{
			get {return UtDmxnProvider as SqlUtDmxnProvider;}
		}
		
		#endregion
		
		
		#region "PhanLoaiBenhNhanProvider"
			
		private SqlPhanLoaiBenhNhanProvider innerSqlPhanLoaiBenhNhanProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="PhanLoaiBenhNhan"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override PhanLoaiBenhNhanProviderBase PhanLoaiBenhNhanProvider
		{
			get
			{
				if (innerSqlPhanLoaiBenhNhanProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlPhanLoaiBenhNhanProvider == null)
						{
							this.innerSqlPhanLoaiBenhNhanProvider = new SqlPhanLoaiBenhNhanProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlPhanLoaiBenhNhanProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlPhanLoaiBenhNhanProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlPhanLoaiBenhNhanProvider SqlPhanLoaiBenhNhanProvider
		{
			get {return PhanLoaiBenhNhanProvider as SqlPhanLoaiBenhNhanProvider;}
		}
		
		#endregion
		
		
		#region "UtDmuserProvider"
			
		private SqlUtDmuserProvider innerSqlUtDmuserProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="UtDmuser"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override UtDmuserProviderBase UtDmuserProvider
		{
			get
			{
				if (innerSqlUtDmuserProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlUtDmuserProvider == null)
						{
							this.innerSqlUtDmuserProvider = new SqlUtDmuserProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlUtDmuserProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlUtDmuserProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlUtDmuserProvider SqlUtDmuserProvider
		{
			get {return UtDmuserProvider as SqlUtDmuserProvider;}
		}
		
		#endregion
		
		
		#region "LoaiProvider"
			
		private SqlLoaiProvider innerSqlLoaiProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Loai"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override LoaiProviderBase LoaiProvider
		{
			get
			{
				if (innerSqlLoaiProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlLoaiProvider == null)
						{
							this.innerSqlLoaiProvider = new SqlLoaiProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlLoaiProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlLoaiProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlLoaiProvider SqlLoaiProvider
		{
			get {return LoaiProvider as SqlLoaiProvider;}
		}
		
		#endregion
		
		
		#region "PdmqhProvider"
			
		private SqlPdmqhProvider innerSqlPdmqhProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Pdmqh"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override PdmqhProviderBase PdmqhProvider
		{
			get
			{
				if (innerSqlPdmqhProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlPdmqhProvider == null)
						{
							this.innerSqlPdmqhProvider = new SqlPdmqhProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlPdmqhProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlPdmqhProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlPdmqhProvider SqlPdmqhProvider
		{
			get {return PdmqhProvider as SqlPdmqhProvider;}
		}
		
		#endregion
		
		
		#region "LichSuDieuTriProvider"
			
		private SqlLichSuDieuTriProvider innerSqlLichSuDieuTriProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="LichSuDieuTri"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override LichSuDieuTriProviderBase LichSuDieuTriProvider
		{
			get
			{
				if (innerSqlLichSuDieuTriProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlLichSuDieuTriProvider == null)
						{
							this.innerSqlLichSuDieuTriProvider = new SqlLichSuDieuTriProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlLichSuDieuTriProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlLichSuDieuTriProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlLichSuDieuTriProvider SqlLichSuDieuTriProvider
		{
			get {return LichSuDieuTriProvider as SqlLichSuDieuTriProvider;}
		}
		
		#endregion
		
		
		#region "ChuyenOpcBufferProvider"
			
		private SqlChuyenOpcBufferProvider innerSqlChuyenOpcBufferProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="ChuyenOpcBuffer"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ChuyenOpcBufferProviderBase ChuyenOpcBufferProvider
		{
			get
			{
				if (innerSqlChuyenOpcBufferProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlChuyenOpcBufferProvider == null)
						{
							this.innerSqlChuyenOpcBufferProvider = new SqlChuyenOpcBufferProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlChuyenOpcBufferProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlChuyenOpcBufferProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlChuyenOpcBufferProvider SqlChuyenOpcBufferProvider
		{
			get {return ChuyenOpcBufferProvider as SqlChuyenOpcBufferProvider;}
		}
		
		#endregion
		
		
		#region "DieuTriProvider"
			
		private SqlDieuTriProvider innerSqlDieuTriProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="DieuTri"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override DieuTriProviderBase DieuTriProvider
		{
			get
			{
				if (innerSqlDieuTriProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlDieuTriProvider == null)
						{
							this.innerSqlDieuTriProvider = new SqlDieuTriProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlDieuTriProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlDieuTriProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlDieuTriProvider SqlDieuTriProvider
		{
			get {return DieuTriProvider as SqlDieuTriProvider;}
		}
		
		#endregion
		
		
		#region "PdmphxaProvider"
			
		private SqlPdmphxaProvider innerSqlPdmphxaProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Pdmphxa"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override PdmphxaProviderBase PdmphxaProvider
		{
			get
			{
				if (innerSqlPdmphxaProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlPdmphxaProvider == null)
						{
							this.innerSqlPdmphxaProvider = new SqlPdmphxaProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlPdmphxaProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlPdmphxaProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlPdmphxaProvider SqlPdmphxaProvider
		{
			get {return PdmphxaProvider as SqlPdmphxaProvider;}
		}
		
		#endregion
		
		
		#region "PdmdtProvider"
			
		private SqlPdmdtProvider innerSqlPdmdtProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Pdmdt"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override PdmdtProviderBase PdmdtProvider
		{
			get
			{
				if (innerSqlPdmdtProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlPdmdtProvider == null)
						{
							this.innerSqlPdmdtProvider = new SqlPdmdtProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlPdmdtProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlPdmdtProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlPdmdtProvider SqlPdmdtProvider
		{
			get {return PdmdtProvider as SqlPdmdtProvider;}
		}
		
		#endregion
		
		
		#region "PdmnnProvider"
			
		private SqlPdmnnProvider innerSqlPdmnnProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Pdmnn"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override PdmnnProviderBase PdmnnProvider
		{
			get
			{
				if (innerSqlPdmnnProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlPdmnnProvider == null)
						{
							this.innerSqlPdmnnProvider = new SqlPdmnnProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlPdmnnProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlPdmnnProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlPdmnnProvider SqlPdmnnProvider
		{
			get {return PdmnnProvider as SqlPdmnnProvider;}
		}
		
		#endregion
		
		
		#region "UtTinhProvider"
			
		private SqlUtTinhProvider innerSqlUtTinhProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="UtTinh"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override UtTinhProviderBase UtTinhProvider
		{
			get
			{
				if (innerSqlUtTinhProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlUtTinhProvider == null)
						{
							this.innerSqlUtTinhProvider = new SqlUtTinhProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlUtTinhProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlUtTinhProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlUtTinhProvider SqlUtTinhProvider
		{
			get {return UtTinhProvider as SqlUtTinhProvider;}
		}
		
		#endregion
		
		
		#region "PdmnclnProvider"
			
		private SqlPdmnclnProvider innerSqlPdmnclnProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Pdmncln"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override PdmnclnProviderBase PdmnclnProvider
		{
			get
			{
				if (innerSqlPdmnclnProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlPdmnclnProvider == null)
						{
							this.innerSqlPdmnclnProvider = new SqlPdmnclnProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlPdmnclnProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlPdmnclnProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlPdmnclnProvider SqlPdmnclnProvider
		{
			get {return PdmnclnProvider as SqlPdmnclnProvider;}
		}
		
		#endregion
		
		
		
		#region "General data access methods"

		#region "ExecuteNonQuery"
		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteNonQuery(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteNonQuery(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		public override void ExecuteNonQuery(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			database.ExecuteNonQuery(commandWrapper);	
			
		}

		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		public override void ExecuteNonQuery(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			database.ExecuteNonQuery(commandWrapper, transactionManager.TransactionObject);	
		}


		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteNonQuery(commandType, commandText);	
		}
		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteNonQuery(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#region "ExecuteDataReader"
		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteReader(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			Database database = transactionManager.Database;
			return database.ExecuteReader(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteReader(commandWrapper);	
		}

		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			Database database = transactionManager.Database;
			return database.ExecuteReader(commandWrapper, transactionManager.TransactionObject);	
		}


		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteReader(commandType, commandText);	
		}
		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteReader(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#region "ExecuteDataSet"
		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteDataSet(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			Database database = transactionManager.Database;
			return database.ExecuteDataSet(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteDataSet(commandWrapper);	
		}

		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			Database database = transactionManager.Database;
			return database.ExecuteDataSet(commandWrapper, transactionManager.TransactionObject);	
		}


		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteDataSet(commandType, commandText);	
		}
		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteDataSet(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#region "ExecuteScalar"
		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override object ExecuteScalar(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteScalar(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override object ExecuteScalar(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			Database database = transactionManager.Database;
			return database.ExecuteScalar(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override object ExecuteScalar(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteScalar(commandWrapper);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override object ExecuteScalar(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			Database database = transactionManager.Database;
			return database.ExecuteScalar(commandWrapper, transactionManager.TransactionObject);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override object ExecuteScalar(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteScalar(commandType, commandText);	
		}
		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override object ExecuteScalar(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteScalar(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#endregion


	}
}
